package com.tx.framework.util;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

public class CommonUtil {

	/**
	 * 检查list不为空
	 * 
	 * @param list
	 * @return
	 */
	public static boolean checkList(List<?> list){
		if(list !=null && list.size() >0){
			return true;
		}
		return false;
	}
	
	/**
	 * 获取文件浏览URL
	 * 
	 * @param fileName
	 * @param request
	 * @return
	 */
	public static String getFileURL(String fileName,HttpServletRequest request){
		String url=request.getHeader("X-Forwarded-Scheme")+"://"+request.getServerName()+request.getContextPath()+"/resources/"+fileName;
		return url;
	}
	
	/**
	 * 获取文件浏览基础URL
	 * 
	 * @param request
	 * @return
	 */
	public static String getFileBaseURL(HttpServletRequest request) {
		String url = request.getHeader("X-Forwarded-Scheme") + "://" + request.getServerName()+ request.getContextPath()+ "/resources/";
		return url;
	}

	/**
	 * 检查wx请求返回值是否包含errorcode，true 不包含，false 包含
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static Boolean checkResponseNoError(String response){
		Map<String,Object> map=JSONUtil.jsonToT(response, Map.class);
		if(!map.containsKey("errcode") || map.get("errcode").toString().equals("0")){
			return true;
		}
		return false;
	}
	
	public static Integer null2Zero(Integer itg){
		if(itg ==null){
			return 0;
		}
		return itg;
	}

	
}
